/*
select top 1000 * from limitazioni
select count(*) from corse where datapart >='2014-12-18 00:00:00'


select * from limitazioni where id_linea in (select id_linea from corse where datapart >='2014-12-18 00:00:00')

update limitazioni set codprov='*' 
where id_linea in (select id_linea from corse where datapart >='2014-12-18 00:00:00')
*/

declare @id_linea char(14)
declare cursore cursor for select id_linea from corse where datapart >='2014-12-18 00:00:00' and id_linea not in (select id_linea from limitazioni)
open cursore
fetch next from cursore into @id_linea
while @@fetch_status>=0
begin
insert into limitazioni (id_linea, catkey, codprov, cod_locale, cod_cfg_linea, coditinera)
values (@id_linea, 1000,'*','*','*','*')
fetch next from cursore into @id_linea
end
close cursore
deallocate cursore